<?php
class AppController extends Controller {
	var $helpers = array('Javascript', 'Html', 'Ajax', 'CandidateSelector');

	var $User;
	var $Ballot;
	var $Role;
	var $Auth;
	var $Session;
	var $RequestHandler;
	

	var $components = array('Acl', 'Auth', 'Cookie');
	
	var $uses = array('User');

	var $Issues = array(
    "Civil Rights" => array("Discrimination", "Gender", "Gay Lesbian LGBT", "Women"),

    "Crime" => array("Drugs", "Gun", "Violence", "Defense Military"),
    "Defense and Military" => array("Afghanistan", "Al Qaeda", "Homeland Security", "Iran", 
                                    "Iraq", "National Guard", "Terrorism", "Torture", "War"),

    "Domestic Social Issues" => array("Abortion", "Family Children", "Health Healthcare", 
                                      "Infrastructure", "Social Security", "Welfare Poverty"),

      "Economy" => array("Budget", "Deficit", "Immigration", "Jobs", "Labor", 
                          "Minimum Wage", "Taxes", "Trade"),

      "Education" => array("Schools", "School Budget", "School Violence", "Teacher Salary"),

      "Environment" => array("Conservation", "Energy", "Global Warming", "Growth", 
                            "Nuclear Power", "Oil Gas Petrolium", "Waste"),

      "Ethics" => array("Campaign Finance", "Corruption", "Government Reform", "Values"),


      "Foreign Policy" => array("Africa", "China", "Europe", "Free Trade", "Immigration", 
                                "Israel", "Latin America", "Middle East", "Russia"),

      "Science Technology" => array("Biotechnology", "Internet", "Stem Cells", "NASA Space")
	);

	function beforeFilter() {
		if(isset($this->Auth)) {
			if($this->viewPath == 'pages')
			//here we are saying to the Auth that if we are viewing static pages
			//(usually in /views/pages/) we allow every action (ie: mainly display)
			$this->Auth->allow('*');
			else {
				//we also set the Login action to our users/login
				$this->Auth->loginAction = '/users/login';
				//By using actions, Auth will make use of ACL and check with AclComponent::check(). An isAuthorized function is not needed.
				//By using crud, Auth will make use of ACL and check with AclComponent::check(). Actions should be mapped to CRUD (see mapActions).
				$this->Auth->authorize = 'actions';
				$this->Auth->actionPath = 'controllers/';

			}
		}
		if($this->Session->check('Auth.User')) {
      $user_id = $this->Session->read('Auth.User.id');
      $data = $this->User->read(null, $user_id);
      if (!empty($data['PersonalProfile'])) {
      	$interests = explode(',', $data['PersonalProfile']['political_interests']);
        $this->Issues['Personal Interests'] = $interests;
        //Debugger::dump($this->Issues);
      }
		}
		$this->set('acl', $this->Acl);
		$this->set('issues', $this->Issues);
	}
}
?>